package com.maori.languageapp.discover.songs;
import java.util.ArrayList;
import java.util.HashMap;
import com.maori.languageapp.R;
import com.maori.languageapp.consts.ImageLoader;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Maori_Discover_Song_Adapter extends BaseAdapter {
	// Declare Variables
	Context context;
	LayoutInflater inflater;
	ArrayList<HashMap<String, String>> data;
	ImageLoader imageLoader;

	public Maori_Discover_Song_Adapter(Context context,
			ArrayList<HashMap<String, String>> arraylist) {
		this.context = context;
		data = arraylist;
		imageLoader = new ImageLoader(context);

	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		// Declare Variables
		TextView maori_title, english_title;
		TextView maori_synonym_title, english_synonym_title;
		TextView country;
		TextView Synonims, Audios, Images, Videos, Likes;
		ImageView flag;
		Button discover_bookmark;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View itemView = inflater.inflate(R.layout.maori_discover_main_list_raw,
				parent, false);
		View itemViewSynonym = inflater.inflate(
				R.layout.languageapp_discover_synonyms, parent, false);

		// Get the position from the results
		HashMap<String, String> resultp = new HashMap<String, String>();
		resultp = data.get(position);

		// Locate the TextViews in listview_item.xml
		maori_title = (TextView) itemView.findViewById(R.id.discover_maori_title);
		english_title = (TextView) itemView.findViewById(R.id.discover_english_title);
		Synonims = (TextView) itemView.findViewById(R.id.textrawtxta);
		Audios = (TextView) itemView.findViewById(R.id.textrawtxtb);
		Images = (TextView) itemView.findViewById(R.id.textrawtxtc);
		Videos = (TextView) itemView.findViewById(R.id.textrawtxtd);
		Likes = (TextView) itemView.findViewById(R.id.textrawtxte);
		discover_bookmark = (Button) itemView.findViewById(R.id.discover_bookmark);
		// Locate the ImageView in listview_item.xml
		flag = (ImageView) itemView.findViewById(R.id.mem_discover_img);

		// Display Synonyms
		maori_synonym_title = (TextView) itemViewSynonym.findViewById(R.id.maori_synonym_title);
		english_synonym_title = (TextView) itemViewSynonym.findViewById(R.id.english_synonym_title);

		// Capture position and set results to the TextViews
		maori_title.setText(resultp.get(Maori_Discover_Song.word));
		english_title.setText(resultp.get(Maori_Discover_Song.wordb));
		

		// Print Bottom Raw Count details
		Synonims.setText(resultp.get(Maori_Discover_Song.TotalsSynonim));
		Audios.setText(resultp.get(Maori_Discover_Song.TotalAudios));
		Images.setText(resultp.get(Maori_Discover_Song.TotalImages));
		Videos.setText(resultp.get(Maori_Discover_Song.TotalVideos));
		Likes.setText(resultp.get(Maori_Discover_Song.TotalsLikes));
		discover_bookmark.setText(resultp.get(Maori_Discover_Song.NID));
		// Capture position and set results to the ImageView
		// Passes flag images URL into ImageLoader.class to download and cache
		// images
		imageLoader.DisplayImage(resultp.get(Maori_Discover_Song.M_Source),
				flag);
		// Capture button clicks on ListView items
		itemView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// Get the position from the results
				HashMap<String, String> resultp = new HashMap<String, String>();
				resultp = data.get(position);
				// Send single item click data to SingleItemView Class
				Intent intent = new Intent(context,
						Maori_Discover_Song_Details.class);
				
				intent.putExtra("word", resultp.get(Maori_Discover_Song.word));
				intent.putExtra("wordcontent", resultp.get(Maori_Discover_Song.wordcontent));
				intent.putExtra("maori", resultp.get(Maori_Discover_Song.wordb));
				intent.putExtra("maoricontent", resultp.get(Maori_Discover_Song.wordcontentb));
				intent.putExtra("nid", resultp.get(Maori_Discover_Song.NID));
				intent.putExtra("Source",resultp.get(Maori_Discover_Song.M_Source));
				intent.putExtra("MID", resultp.get(Maori_Discover_Song.MID));
				intent.putExtra("first_name",resultp.get(Maori_Discover_Song.first_name));
				intent.putExtra("last_name",resultp.get(Maori_Discover_Song.last_name));
				intent.putExtra("tribe", resultp.get(Maori_Discover_Song.tribe));
				intent.putExtra("userimage",resultp.get(Maori_Discover_Song.userimage));
				intent.putExtra("TotalsSynonim", resultp.get(Maori_Discover_Song.TotalsSynonim));
				intent.putExtra("TotalAudios", resultp.get(Maori_Discover_Song.TotalAudios));
				intent.putExtra("TotalImages", resultp.get(Maori_Discover_Song.TotalImages));
				intent.putExtra("TotalVideos", resultp.get(Maori_Discover_Song.TotalVideos));
				intent.putExtra("TotalsLikes", resultp.get(Maori_Discover_Song.TotalsLikes));
				
				
				context.startActivity(intent);

			}
		});

		return itemView;
	}
}
